package com.admin.action.library_page_action;

import com.admin.Action;
import com.admin.service.borservice.BorService;
import com.admin.service.borservice.BorServiceImpl;
import com.pojo.AdminBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class SuperAdminAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }

        AdminBean adminBean= (AdminBean) session.getAttribute("adminInfo");

        BorService borService = new BorServiceImpl();
        Double borinfoSum=borService.borinfoSum();//书籍借阅的收入，
        Double bookPrice=borService.booksInfoSum();//书籍的价值（包括已下架的书籍）相当于总产值
        Long level=adminBean.getAdminLevel();
        String superName=adminBean.getAdminName();
//        Long level=2L;
        if(level==2){
            String str1 = "[{\"borinfoSum\":"+borinfoSum+",\"bookPrice\":"+bookPrice+",\"superName\":\""+superName+"\"}]";
            System.out.println(str1);
            out.print(str1);
        }else if(level==1){
            String str1 = "[{\"ret\":"+false+"}]";
            System.out.println(str1);
            out.print(str1);
        }



    }
}
